/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-08-13
 * Time: 22:37
 */
// https://leetcode.cn/problems/number-of-segments-in-a-string/submissions/
class Solution2 {
    public int countSegments(String s) {
        s = s.trim();
        if (s.isEmpty()) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == ' ' && s.charAt(i+1)!= ' ') {
                count++;
            }
        }
        return count+1;
    }
}